from tools import *


class StgParams:

    def getParamsByClass(self, clsArr):
        stgParams = {}
        for clsName in clsArr.keys():
            if not hasattr(self, clsName):
                stgParams[clsName] = []
            fun = getattr(self, clsName)
            stgParams = fun()
            break
        return stgParams

    def getOneParamsByClass(self, clsName):
        fun = getattr(self, clsName)
        return fun()
        # stgParams = {}
        # for clsName in clsArr.keys():
        #     if not hasattr(self, clsName):
        #         stgParams[clsName] = []
        #     fun = getattr(self, clsName)
        #     stgParams = fun()
        # return stgParams

    def DoubleSMA(self):
        fastPeriods = mathTool.getFibonacci(1, 90)
        slowPeriods = mathTool.getFibonacci(1, 180)
        paramsArr = []
        for fastPeriod in fastPeriods:
            for slowPeriod in slowPeriods:
                if fastPeriod < slowPeriod:
                    params = {}
                    params['fastPeriod'] = fastPeriod
                    params['slowPeriod'] = slowPeriod
                    paramsArr.append(params)
        return paramsArr

    def DoubleMaStg2(self):
        fastPeriods = mathTool.getFibonacci(5, 90)
        slowPeriods = mathTool.getFibonacci(5, 180)
        paramsArr = []
        for fastPeriod in fastPeriods:
            for slowPeriod in slowPeriods:
                if fastPeriod < slowPeriod:
                    params = {}
                    params['fastPeriod'] = fastPeriod
                    params['slowPeriod'] = slowPeriod
                    paramsArr.append(params)
        return paramsArr

    def DoubleMaStg(self):
        paramsArr = []
        fasts = [5, 10, 20, 40, 60, 80, 100]
        slows = [20, 40, 60, 80, 100, 120, 140, 160, 180, 200]
        for item in fasts:
            for item2 in slows:
                if item < item2:
                    paramsArr.append({"fastPeriod": item, "slowPeriod": item2})
        return paramsArr

    def SingleMaStg(self):
        params = [
            {'period': 10},
            {'period': 15},
            {'period': 20},
            {'period': 30},
            {'period': 40},
            {'period': 50},
            {'period': 60}
        ]
        return params

    def MACDStg(self):
        base = {'fastPeriod': 12, 'slowPeriod': 26, 'signalPeriod': 9}
        params = []
        # for multi in [1, 2, 3, 4, 6, 8, 10, 15]:
        #     params.append(
        #         {'fastPeriod': base['fastPeriod'] * multi, 'slowPeriod': base['slowPeriod'] * multi,
        #          'signalPeriod': base['signalPeriod'] * multi})
        for buy in ['overUP', 'belowUp', 'belowUpX', 'up']:
            for sell in ['overDown', 'belowDown', 'overDownX2', 'down']:
                base2 = base.copy()
                base2['buy'] = buy
                base2['sell'] = sell
                params.append(base2)
        return params

    def KDJStg(self):
        base = {'period': 9, 'smooth': 3, 'superBuyPoint': 80}  # 超买超卖
        params = [
            {'period': 5, 'smooth': 3, 'buySell': 'x', 'superBuyPoint': 90},  # 金叉死叉
            {'period': 5, 'smooth': 3, 'buySell': 'over', 'superBuyPoint': 90}  # 金叉死叉
        ]
        for period in [5, 9, 19, 36]:
            for buySell in ['over', 'x']:
                base2 = base.copy()
                base2['period'] = period
                base2['buySell'] = buySell
                params.append(base2)
        return params

    def BollStg(self):
        params = []
        for item in ['pressSupport', 'trend', 'openTrade']:
            for item2 in [5, 10, 20, 30, 50]:
                params.append({'timeperiod': item2, 'type': item, 'nbdev': 2})
        return params


stgParams = StgParams()
